// 2025/11/21
// 搜索二维矩阵

class Solution {
public:
    bool searchMatrix(vector<vector<int>>& matrix, int target) {
        int m = matrix.size(), n = matrix[0].size();
        int l = 0, r = m - 1, aim = 0;
        while(l <= r)
        {
            int mid = (l + r) >> 1;
            if(matrix[mid][0] <= target)
            {
                aim = mid;
                l = mid + 1;
            }
            else
                r =  mid - 1;
        }
        vector<int>& nums = matrix[aim];
        l = 0, r = n - 1, aim = 0;
        while(l <= r)
        {
            int mid = (l + r) >> 1;
            if(nums[mid] < target)
                l = mid + 1;
            else if(nums[mid] > target)
                r = mid - 1;
            else
                return true;
        }
        return false;
    }
};